#!/bin/bash

#1. lowcode-engine-ext->lowcode-engine-ext
#2. lowcode-engine -> lowcode-engine
#3. material -> assets
#4. demo-graph-x6 -> css and js
current_dir=$(pwd)
# Prompt for folder address
read -p "Enter the folder address of editor: " folder_address

# Check if the folder exists
if [ ! -d "$folder_address" ]; then
  echo "Error: Folder '$folder_address' does not exist."
  exit 1
fi

echo 'compile lowcode-engine-ext?'
read y
if [ "$y" == "y" ]; then
  cd "$folder_address/lowcode-engine-ext/"
  npm run local-build
  yes | cp -rf dist/* "$current_dir/src/main/resources/editor/lowcode-engine-ext"
  echo 'build lowcode-engine-ext done'
else
  echo "skip the compilation of lowcode-engine-ext"
fi

echo 'compile lowcode-engine?'
read y
if [ "$y" == "y" ]; then
  cd "$folder_address/lowcode-engine/packages/engine/"
  npm run build
  yes | cp -rf dist/* "$current_dir/src/main/resources/editor/lowcode-engine"
  echo 'build lowcode-engine done'
else
  echo "skip the compilation of lowcode-engine"
fi

echo 'compile material?'
read y
if [ "$y" == "y" ]; then
  cd "$folder_address/lowcode-businessflow-material/"
  npm run lowcode:build
  yes | cp -rf build/lowcode/* "$current_dir/src/main/resources/editor/assets"
echo 'build material done'
else
  echo "skip the compilation of material"
fi

echo 'compile designer?'
read y
if [ "$y" == "y" ]; then
  cd "$folder_address/lowcode-businessflow-designer/"
  npm run local-build
  yes | cp -rf build/* "$current_dir/src/main/resources/editor/."
  echo 'build designer done'
else
  echo "skip the compilation of designer"
fi
